package II;

/**
 * @author admin
 * 剑指 Offer11 53 - II. 0～n-1中缺失的数字
 * 解题思路：二分查找算法
 */
public class Offer53 {

    public int missingNumber(int[] nums) {

        int left = 0;
        int right = nums.length - 1;
        while (left <= right){
            int mid = (left + right)/2;
            if (nums[mid] == mid){
                left = mid + 1;
            }else {
                right = mid - 1;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        System.out.println(new Offer53().missingNumber(new int[]{0,1,3}));
    }
}
